package com.platform.api;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.platform.annotation.IgnoreAuth;
import com.platform.entity.FarmChapterEntity;
import com.platform.entity.FarmContentEntity;
import com.platform.service.FarmContentService;
import com.platform.util.ApiBaseAction;
import com.platform.utils.PageUtils;
import com.platform.utils.Query;
import com.platform.utils.R;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * 内容表四级Controller
 *
 * @author lipengjun
 * @email 939961241@qq.com
 * @date 2020-02-10 22:01:54
 */
@RestController
@RequestMapping("/api/content")
public class FarmContentController extends ApiBaseAction{
    @Autowired
    private FarmContentService farmContentService;

    /**
     * 根据parentId查询数据接口
     */
    @ApiOperation(value = "查询农机单元页全部信息")
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "农机手册id", paramType = "path", required = true)})
    @IgnoreAuth
    @GetMapping(value = "fbPd")
    public Object findByParentId(@RequestParam(value = "id")Integer id) {
    	List<FarmContentEntity> list=farmContentService.findByParentId(id);
    	
    	return toResponsSuccess(list);
    }
    /**
     * 查看列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("farmcontent:list")
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<FarmContentEntity> farmContentList = farmContentService.queryList(query);
        int total = farmContentService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(farmContentList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    /**
     * 查看信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("farmcontent:info")
    public R info(@PathVariable("id") Integer id) {
        FarmContentEntity farmContent = farmContentService.queryObject(id);

        return R.ok().put("farmContent", farmContent);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("farmcontent:save")
    public R save(@RequestBody FarmContentEntity farmContent) {
        farmContentService.save(farmContent);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("farmcontent:update")
    public R update(@RequestBody FarmContentEntity farmContent) {
        farmContentService.update(farmContent);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("farmcontent:delete")
    public R delete(@RequestBody Integer[] ids) {
        farmContentService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<FarmContentEntity> list = farmContentService.queryList(params);

        return R.ok().put("list", list);
    }
}
